package com.bulletelc.apollopre.framework;

import android.os.Bundle;
import android.support.annotation.Nullable;

/**
 * author: lhl
 * date  : 2017/11/15
 * desc  : MVP架构的Activity基类,预防内存泄漏；使用到MVP架构的Activity都继承于此类
 */

public abstract class MVPBaseActivity<V extends IView ,P extends IPresenter<V>> extends BaseActivity implements IView{
    protected P presenter;

    @Override
    protected void onDestroy() {
        super.onDestroy();
        presenter.detachView(false);
        presenter.stop();
    }

    @Override
    protected void setPresenter() {
        presenter=createPresenter();
        presenter.attachView((V) this);
    }

    /**
     * 创建Presenter对象
     * @return
     */
    protected abstract P createPresenter();
}
